/**
 * This file is part of Wireless TransFer.
 *
 *   Wireless TransFer is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *	
 *   Wireless TransFer is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Wireless TransFer.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	 Copyright (C) 2011
 *   @author skalman
 */

package com.wirelesstransfer.activity.status;

import java.io.File;
import java.util.List;
import java.util.Map;

import com.wirelesstransfer.activity.filebrowser.FileSize;
import com.wirelesstransfer.client.ApacheClient;
import com.wirelesstransfer.server.ConnectedClients.ConnectedClient;
import com.wirelesstransfer.server.ConnectedClients.ConnectedClientsHandler;

public class ConnectionInformation {
	private List<ConnectedClient> c;
	private List<File> f;
	
	private ApacheClient client;
	
	/**
	 * Total size of downloaded files.
	 * 
	 * @return Total file size (MB).
	 */
	public Map<String, String> getUploadedSize() {
		// TODO What about the current file?
		long fileSize = 0;
		c = ConnectedClientsHandler.getInstance().getConnectedClients();
		
		for(int i = 0; i < c.size(); i++) {
			f = c.get(i).getReceivedFiles();
			
			if(f != null) {
				for(int j = 0; j < f.size(); j++) {
					fileSize += f.get(j).length();
				}
			}
		}
		
		return FileSize.getFileSize(fileSize);
	}
	
	public Map<String, String> getDownloadSize() {
		long fileSize = 0;
		client = ApacheClient.getInstance();
		if(client.getConnection() != null) {
			f = client.getConnection().getTransferData().getReceivedFiles();

			if(f != null) {
				for(int i = 0; i < f.size(); i++) {
					fileSize += f.get(i).length();
				}
			}

			// Add the downloaded part of the current file.
			File c =  client.getConnection().getTransferData().getCurrentFile();
			//		File c = ReceivedData.getInstance().getCurrentFile();
			if(c != null) {
				fileSize += client.getConnection().getTransferData().getCurrentFile().length();
			}
		}
		return FileSize.getFileSize(fileSize);
	}
}
